package com.rmy.publish.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.rmy.common.config.RmyConfig;
import com.rmy.common.utils.ffmpeg.FFMpegUtil;
import com.rmy.common.utils.file.FileEntity;
import com.rmy.common.utils.file.FileUploadUtils;
import com.rmy.common.utils.file.FileUtils;
import com.rmy.common.utils.file.MimeTypeUtils;
import com.rmy.framework.config.ServerConfig;
import org.apache.commons.io.FilenameUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.rmy.common.annotation.Log;
import com.rmy.common.core.controller.BaseController;
import com.rmy.common.core.domain.AjaxResult;
import com.rmy.common.enums.BusinessType;
import com.rmy.publish.domain.MipsMaterialFiles;
import com.rmy.publish.service.IMipsMaterialFilesService;
import com.rmy.common.utils.poi.ExcelUtil;
import com.rmy.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 素材管理Controller
 *
 * @author rmy
 * @date 2023-05-17
 */
@RestController
@RequestMapping("/publish/mipsMaterialFiles")
public class MipsMaterialFilesController extends BaseController
{
    @Autowired
    private IMipsMaterialFilesService mipsMaterialFilesService;

    @Autowired
    private ServerConfig serverConfig;

    /**
     * 查询素材管理列表
     */
    @PreAuthorize("@ss.hasPermi('publish:mipsMaterialFiles:list')")
    @GetMapping("/list")
    public TableDataInfo list(MipsMaterialFiles mipsMaterialFiles)
    {
        startPage();
        List<MipsMaterialFiles> list = mipsMaterialFilesService.selectMipsMaterialFilesList(mipsMaterialFiles);
        return getDataTable(list);
    }

    /**
     * 导出素材管理列表
     */
    @PreAuthorize("@ss.hasPermi('publish:mipsMaterialFiles:export')")
    @Log(title = "素材管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MipsMaterialFiles mipsMaterialFiles)
    {
        List<MipsMaterialFiles> list = mipsMaterialFilesService.selectMipsMaterialFilesList(mipsMaterialFiles);
        ExcelUtil<MipsMaterialFiles> util = new ExcelUtil<MipsMaterialFiles>(MipsMaterialFiles.class);
        util.exportExcel(response, list, "素材管理数据");
    }

    /**
     * 获取素材管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('publish:mipsMaterialFiles:query')")
    @GetMapping(value = "/{materialId}")
    public AjaxResult getInfo(@PathVariable("materialId") Long materialId)
    {
        return AjaxResult.success(mipsMaterialFilesService.selectMipsMaterialFilesByMaterialId(materialId));
    }

    /**
     * 新增素材管理
     */
    @PreAuthorize("@ss.hasPermi('publish:mipsMaterialFiles:add')")
    @Log(title = "素材管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody List<MipsMaterialFiles> mipsMaterialFilesList)
    {
        int nRet = 0;
        String strIds = "";
        for (MipsMaterialFiles mipsMaterialFiles : mipsMaterialFilesList) {
            nRet = mipsMaterialFilesService.insertMipsMaterialFiles(mipsMaterialFiles);
            strIds = strIds+mipsMaterialFiles.getMaterialId()+",";
        }
        return toAjax(nRet).put("ids", strIds);
    }

    /**
     * 修改素材管理
     */
    @PreAuthorize("@ss.hasPermi('publish:mipsMaterialFiles:edit')")
    @Log(title = "素材管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MipsMaterialFiles mipsMaterialFiles)
    {
        return toAjax(mipsMaterialFilesService.updateMipsMaterialFiles(mipsMaterialFiles));
    }

    /**
     * 删除素材管理
     */
    @PreAuthorize("@ss.hasPermi('publish:mipsMaterialFiles:remove')")
    @Log(title = "素材管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{materialIds}")
    public AjaxResult remove(@PathVariable Long[] materialIds)
    {
        return toAjax(mipsMaterialFilesService.deleteMipsMaterialFilesByMaterialIds(materialIds));
    }

}
